package 练习.特别数的和;

import java.util.Scanner;

public class test {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int i = sc.nextInt();
		int count =0;
		String[] str = new String[i+1];
		for (int j = 1; j <= i; j++) {
			str[j] = j+"";
			if(str[j].contains("2") || str[j].contains("0") || str[j].contains("1") || str[j].contains("9")){
				count+=Integer.parseInt(str[j]);
			}
		}
		System.out.println(count);
	}
}